//QML与Qt C++ 交互参考博客
//https://www.bbsmax.com/A/QV5Z98G6Jy/
//https://blog.csdn.net/baidu_33850454/category_7939885.html
//https://blog.51cto.com/waleon/5525379
//https://blog.51cto.com/u_15127501/3380053?articleABtest=0
//https://blog.51cto.com/u_15651175/5547442?articleABtest=0
//https://blog.51cto.com/wangjichuan/5691556



// 下面是导入语句
import QtQuick 2.9
import QtQuick.Window 2.2

/* QML文档可以看做是一个QML对象树,这里创建了Window根对象
和它的子对象Text */
Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    QmlTest2 {
x:10; y:10
    }


    ColorText {
        anchors.centerIn: parent

        mycolorText: qsTr("hello 千万千万千万千瓦器!")
        mytextFont.underline: true

        //在该组件创建完成后，调用一次函数
        Component.onCompleted: {
            changeDuration(2000)
            myclicked.connect(myTestFunc) // 信号槽绑定
        }

        onMyclicked: {
                console.log("colorButton: ", buttonColor)

                var value = buttonColor
                switch(value) {
                case "#ff0000":
                    backImg.source = "images/bg2.png";
                    mycolorText: qsTr("11111111")
                    break;
                case "#0000ff":
                    backImg.source = "images/bg3.png";
                    mycolorText = "22222222";
                    break;
                default:
                    backImg.source = "images/bg1.png";
                    mycolorText = "33333333";
                }
                changeDuration(2000)
            }

        onMycolorTextChanged: console.log("我的自定义属性被修改了: ")
    }

    Image {
        id: backImg
        source: "images/bg1.png"
        width: parent.width
        anchors.bottom: parent.bottom
        fillMode: Image.PreserveAspectFit //缩放图片时会保持宽高比不变
    }
}
